import sys

import os

files = sys.argv[1:]

for file in files:
        print os.popen('mv %s %s.bak'%(file,file)).read()
        if ('.png') in file:
          print os.popen('pngcrush -reduce -brute %s.bak %s' % (file,file)).read()
        elif '.jpg' in file:
           print os.popen('jpegtran -optimize %s.bak > %s' % (file,file)).read()

